<template>
	<view class="container">
		<view class="card">
			<view class="text-box">
				<view class="title">个人信息设置</view>
				<view class="text">拨打电话时将个人基本信息及位置信息推送给物业人员</view>
			</view>
			<view class="switch-box" @tap="switch_btn">
				<view class="switch" :class="isswitch? 'switch1':''">
					<view class="switch-mini" :class="isswitch? 'switch-mini1':''"></view>
				</view>
			</view>
		</view>
		<view class="clickAlarm" @tap="callphone">
			<image src="../../../static/images/clickAlarm.png" mode="" class="alarm-img"></image>
		</view>
	</view>
</template>

<script>
	var common = require('../../../utils/common.js');
	var app = getApp();
	var _this;
	const getaddress = () => {
		if (_this.longitude == '' || _this.latitude == '') {
		uni.getLocation({
			type: 'gcj02',
			success: function(res) {
				console.log('当前位置的经度：' + res.longitude);
				console.log('当前位置的纬度：' + res.latitude);
				common.changeLocation('getLocation_msg', _this, res.longitude, res.latitude, 'gcj02');
			},
			fail: function(res) {
				console.log('定位失败：', res);
				gettaskList()
			}
		});
		}else{
			gettaskList()
		}
	};
	const gettaskList = () => {
		common.post('HouseApi&a=tel_alarm_phone', {
			village_id:_this.village_id,
			pigcms_id:_this.pigcms_id,
			long: _this.longitude,
			lat: _this.latitude,
		}, data => {
			console.log('++++', data)
		});
	};
	//获取手机号码
	const getalarmPhone = () => {
		common.post('HouseApi&a=tel_info', {
			village_id:_this.village_id,
			pigcms_id:_this.pigcms_id,
		}, data => {
			console.log('++++', data)
			if(data.tel_alarm_phone == null){
				uni.showModal({
					title: common.changeTxt('提示'),
					content: common.changeTxt('该小区暂未添加紧急联系电话'),
					showCancel: false,
					confirmText: common.changeTxt('好的'),
					success: function(res) {
						if (res.confirm) {
							uni.navigateBack()
						}
					}
				});
			}else{
				_this.phone = data.tel_alarm_phone;
				if(_this.isswitch == true){
					getaddress()
				}else{
					
				}
			}
		});
	};
	export default {
		data() {
			return {
				listdata: {},
				numlist: {},
				village_id: 0,
				pigcms_id: 0,
				actcolor: '',
				btn_style: '',
				isswitch:true,
				longitude: '',
				latitude: '',
				phone:'',
			}
		},
		onShow() {
			// #ifdef H5
			common.hideWxShare()
			// #endif
		},
		onLoad(options) {
			_this = this;
			
			// #ifdef H5
			console.log('准备跳小程序页', _this.id);
			common.webToMiniapp(_this.route, options, 'redirect')
			// #endif

			common.setMainColor(_this, function(config) {
				_this.actcolor = config.config.mobile_head_color
				_this.btn_style = 'background-color: ' + _this.actcolor + ';box-shadow:0px 30rpx 30rpx -30rpx ' + _this.actcolor +
					';';

				const res = uni.getStorageSync('village_key');
				if (res) {
					_this.village_id = res.village_id;
					_this.pigcms_id = res.pigcms_id;
					_this.village_name = res.village_name;
				};
				
			});
		},
		methods: {
			switch_btn(){
				_this.isswitch = !_this.isswitch;
				
			},
			callphone(){
				getalarmPhone();
				uni.makePhoneCall({
				    phoneNumber: _this.phone
				});
			},
			getLocation_msg(res) {
				if (res && res.lng) {
					_this.longitude = res.lng;
				}
				if (res && res.lat) {
					_this.latitude = res.lat;
				}
				console.log('反馈信息：', res);
			},
		},
		components: {

		}
	}
</script>

<style>
	page {
		background: #FFFFFF;
	}
	.container {
		margin: 0;
		padding: 0;
	}
	.card {
		margin: 30rpx;
		padding: 30rpx;
		border-radius: 10rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		background: rgb(245, 245, 245);
	}
	.title {
		font-size: 32rpx;
		font-weight: 700;
		line-height: 60rpx;
	}
	.text {
		font-size: 26rpx;
		color: #666666;
	}
	.switch-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 20rpx;
	}
	
	.switch {
		width: 30rpx;
		height: 30rpx;
		border-radius: 30rpx;
		background: #FFFFFF;
		border: 2rpx solid #e1e1e1;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.switch-mini {
		width: 22rpx;
		height: 22rpx;
		border-radius: 22rpx;
		background: #e1e1e1;
	}
	
	.switch1 {
		width: 30rpx;
		height: 30rpx;
		border-radius: 30rpx;
		background: #FFFFFF;
		border: 2rpx solid rgb(29, 126, 247);
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.switch-mini1 {
		width: 22rpx;
		height: 22rpx;
		border-radius: 22rpx;
		background: rgb(29, 126, 247);
	}
	
	.switch-text {
		margin-left: 15rpx;
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 50rpx;
		letter-spacing: 0rpx;
		color: #606060;
	}
	.clickAlarm {
		width: 300rpx;
		height: 300rpx;
		margin: 230rpx auto;
	}
	.alarm-img {
		width: 100%;
		height: 100%;
	}
</style>
